<?php
require_once '../../global.inc.php';
//SESSION中取出会员资料信息
$op = $_GET["op"];
$templateInfo		= $_SESSION["templateInfo"];
if($op =="add"){//新增不用取session
	$instanceInfo 	= "";
	$memberActivityArray	= "";
}else{
	$instanceInfo			= $_SESSION["instanceInfo"];
	$memberActivityArray 	= $_SESSION["memberActivityArray"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../js/Calendar.js"></script>
<script type="text/javascript" src="js/checkForm.js"></script>
<script type="text/javascript" src="js/instance.js"></script>
<title>无标题文档</title>
<style type="text/css">
<!--
body {
	margin-left: 3px;
	margin-top: 0px;
	margin-right: 3px;
	margin-bottom: 0px;
}
.input1 {
	width:100%;
}
textarea {
	width:100%;
	resize:none;
	font-size: 12px;
}
div{margin:0 10px}
.STYLE1  {color: #e1e2e3; font-size: 12px;}
.STYLE6  {color: #000000; font-size: 12px;}
.STYLE10 {color: #000000; font-size: 12px;}
.STYLE19 {color: #344b50; font-size: 12px;}
.STYLE21 {color: #3b6375; font-size: 12px;}
.STYLE22 {color: #295568; font-size: 12px;}

-->
</style>
</head>

<body>
<div align="center">
<?php 
   if($op =="add"){
		echo "<h3>活动实例生成</h3>";
   	}else if($op =="query"){
		echo "<h3>活动实例展示</h3>";
	}else if($op =="edit"){
		echo "<h3>活动实例维护</h3>";
	}else if($op =="score"){
		echo "<h3>活动积分结算</h3>";
	}
?>

</div>
<form action="../../action/instanceAction.php?op=<?php echo $op?>" method="post" onsubmit="return checkInstance()">
<table align="center" width="90%" border="0" cellpadding="3" cellspacing="1" bgcolor="#a8c7ce">
	<input type="hidden" id="activityId" name="activityId" value="<?php echo $templateInfo['activity_id']?>"/>
	<input type="hidden" id="instanceId" name="instanceId" value="<?php echo $instanceInfo['instance_id']?>"/>
	<tr>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">活动名称：</span></div></td>
		<td colspan="7" bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input readonly="readonly" class="input1" type="text" id = "subject" name="subject" value="<?php echo $templateInfo['subject']?>"/></div></td>
	</tr>
	<tr>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">活动内容：</span></div></td>
		<td colspan="7" bgcolor="#FFFFFF" class="STYLE6"><div align="center"><textarea  readonly="readonly" name="travel" id="travel"  rows="20"><?php echo $templateInfo['travel']?>"/></textarea></div></td>
	</tr>
	<tr>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">预估费用：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input readonly="readonly" class="input1" type="text" id = "fee" name="fee" value="<?php echo $templateInfo['fee']?>"/></div></td>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">销售价格：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input class="input1" type="text" id = "saleFee" name="saleFee" value="<?php echo $instanceInfo['sale_fee']?>"/></div></td>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">定金价格：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input class="input1" type="text" id = "frontFee" name="frontFee" value="<?php echo $instanceInfo['front_fee']?>"/></div></td>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">积分比例：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input class="input1" type="text" id = "scorePercent" name="scorePercent" value="<?php echo $instanceInfo['score_percent']?>"/></div></td>
	</tr>
	<tr>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">领队：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input class="input1" type="text" id = "leader" name="leader" value="<?php echo $instanceInfo['leader']?>"/></div></td>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">出发时间：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input class="input1" type="text" id = "travelDate" name="travelDate" value="<?php echo $instanceInfo['travel_date']?>"  onclick="calendar(this)"/></div></td>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">回归时间：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><input class="input1" type="text" id = "backDate" name="backDate" value="<?php echo $instanceInfo['back_date']?>"  onclick="calendar(this)"/></div></td>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">活动状态：</span></div></td>
		<td bgcolor="#FFFFFF" class="STYLE6"><div align="center"><select class="input1"  name='status' id='status'>
        	<?php 
        		if($op=="add"){
					echo "<option  value='1'>活动生成</option>";
				}else{
					$status=$instanceInfo['status'];
					switch ($status) {
						case 0:
							$desc='活动取消'; break;
						case 1:
							$desc='活动生成'; break;
						case 2:
							$desc='活动结束'; break;
						case 3:
							$desc='积分结算'; break;
					}
					echo "<option  value=$status>$desc</option>";
				}
			?>
		</select></div></td>
	<?php if($op !="add"){//生成活动的时候不显示成员
		$rows	 = count($memberActivityArray);//查询一共有多少会员报名
	?>
	<tr>
		<td width="10%" bgcolor="d3eaef" class="STYLE6"><div align="left"><span class="STYLE10">成员构成：</span></div></td>
		<td colspan="7" bgcolor="#FFFFFF" class="STYLE6"><div align="center">
		<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
		<tr height="20">
			<td colspan="12" bgcolor="#FFFFFF" class="STYLE6"><div align="left"><font color="red" >已报名人数：<?php echo $rows?></font><br/></div></td>
		</tr>
	      <tr>
	        <td width="10%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">会员卡号</span></div></td>
	        <td width="8%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">会员姓名</span></div></td>
	        <td width="8%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">会员网名</span></div></td>
	        <td width="10%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">身份证</span></div></td>
	        <td width="10%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">联系电话</span></div></td>
	        <td width="5%"  height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">性别</span></div></td>
	        <td width="5%"  height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">年龄</span></div></td>
	        <td width="8%"  height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">使用积分</span></div></td>
	        <td width="8%"  height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">优惠额度</span></div></td>
	        <td width="8%"  height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">已交定金</span></div></td>
	        <td width="8%"  height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">应收余款</span></div></td>
	        <td   height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">备注</span></div></td>
	      </tr>
	      <?php 
	      $saleFee			= $instanceInfo['sale_fee'];
	      $scorePercent 	= $instanceInfo['score_percent'];
	      foreach ($memberActivityArray as $memberActivity) {
			$memberNo		= $memberActivity["member_no"];			//会员卡号
			$memberName		= $memberActivity["member_name"];		//会员姓名
			$netName		= $memberActivity["net_name"];			//会员网名
			$idNumber		= $memberActivity["id_number"];			//身份证
			$sex			= $memberActivity["sex"];				//会员性别
			$mobile			= $memberActivity["mobile"];			//会员电话
			$old			= substr(date('Y-m-d'),'0','4') - substr($memberActivity["birthday"],0,4);				//会员年龄
			$payScore		= $memberActivity["pay_score"];			//会员本次使用的积分
			$discountFee	= $memberActivity["discount_fee"];		//会员优惠额度
			$payFee			= $memberActivity["pay_fee"];			//会员已交定金
			$remainFee		= $saleFee-$discountFee-$payFee-$payScore;
			$comments		= $memberActivity["comments"];			//备注

			if($sex==1)  $sexName="男";   else $sexName="女";
		    echo "<tr>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$memberNo</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$memberName</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$netName</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$idNumber</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$mobile</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$sexName</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$old</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$payScore</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$discountFee</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$payFee</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$remainFee</span></div></td>";
		        echo "<td height='20' bgcolor='#FFFFFF' class='STYLE19'><div align='center'><span class='STYLE10'>$comments</span></div></td>";
		      echo "</tr>";
		  }
		  ?>
	    </table>
		</div></td>
	</tr>
	<?php }?>
	<tr>
		<td colspan="8" bgcolor="#FFFFFF" colspan="2"><div align="center">
		<?php 
		if($op=="add"){
			echo "<input type='submit' id = 'submit' name='submit'   value='生成活动' />";
		}else if($op=="edit"){
			$instanceId = $instanceInfo['instance_id'];
			if($status=="0"){//取消了的活动只能恢复
				echo "<input type='button' id = 'buttonRenew' name='buttonRenew' value='恢复活动' onclick='renewActivity($instanceId)'/>&nbsp";
			}else if($status=="1"){
				echo "<input type='submit' id = 'submit' name='submit'   value='修改活动' />&nbsp";
				echo "<input type='button' id = 'buttonMember' name='buttonMember'   value='成员维护' onclick='memberActivity($instanceId)'/>&nbsp";
				echo "<input type='button' id = 'buttonCancel' name='buttonCancel'   value='取消活动' onclick='cancelActivity($instanceId)'/>&nbsp";
				echo "<input type='button' id = 'buttonOver' name='buttonOver'   value='活动结束' onclick='overActivity($instanceId)'/>&nbsp";
			}
		}else if($op=="score"){
			echo "<input type='submit' id = 'submit' name='submit'   value='结算积分' />&nbsp";
		}
		?>
		</div></td>
	</tr>
</table>
</form>
</body>
</html>
